package com.ophiux.common.feign.config;

import com.ophiux.common.feign.annotation.EnableOphiuxFeignClients;
import com.ophiux.common.feign.endpoint.FeignClientEndpoint;
import org.springframework.boot.actuate.autoconfigure.endpoint.condition.ConditionalOnAvailableEndpoint;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @desc: feign 自动化配置
 * 将spring.factories配置的：com.ophiux.common.feign.config.OphiuxFeignAutoConfiguration=com.ophiux.system.api.feign.SysLogFeignApi bean注册到容器中
 * @author: hhl
 * @date：2022/7/28 10:21
 */
@Component
@EnableOphiuxFeignClients
@AutoConfigureAfter(EnableOphiuxFeignClients .class)
public class OphiuxFeignAutoConfiguration {

    public OphiuxFeignAutoConfiguration() {
        System.out.println("加载feign自动配置文件");
    }

    /**
     * 扫描有@FeignClient注解的类,注入到spring ioc容器中
     * @param context
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnAvailableEndpoint
    public FeignClientEndpoint feignClientEndpoint(ApplicationContext context) {
        return new FeignClientEndpoint(context);
    }



}
